 package com.howard.webapp.familymanagement.controller;
 
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.google.inject.internal.Lists;
import com.howard.webapp.familymanagement.domain.Menu;
import com.howard.webapp.familymanagement.service.MenuService;

 
@Controller
public class LoginController {
	
	@Autowired
	private MenuService service;
	
	@RequestMapping(value="/login", method = RequestMethod.GET)
	public String login(ModelMap model) {
		System.out.println("login");
		return "login";
 
	}
	
	@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
	public String loginfailed(ModelMap model) {
		System.out.println("loginfailed");
		model.addAttribute("error", "true");
		return "login";
 
	}
	
//	@RequestMapping(value="/logout", method = RequestMethod.GET)
//	public String logout(ModelMap model) {
// 
//		return "login";
// 
//	}
	
	@RequestMapping(value="/denied", method = RequestMethod.GET)
	public String denied(ModelMap model,HttpSession httpSession) {
		System.out.println("denied");
		model.addAttribute("denied", "true");
		return "login";
	}
 
	@RequestMapping(value="/main", method = RequestMethod.GET)
	public String main(ModelMap model, Principal principal, HttpSession httpSession ) {
//		String name = principal.getName();
		String name = "howard";
		List<Menu> menuList = service.findAllMenu();
		model.addAttribute("loginId", name);
	    model.addAttribute("menuList", menuList);
		return "main";
 
	}
 
	@RequestMapping(value="/todo", method = RequestMethod.GET)
	public String todo() {
		System.out.println("todo");
		return "todo";
	}
	
}